<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-31 17:46:49
 * @LastEditTime: 2019-11-28 15:58:02
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../../css/base.css" />
    <link rel="stylesheet" type="text/css" href="../../css/local.css" />
    <link rel="stylesheet" type="text/css" href="../../font/iconfont.css" />
    <link rel="stylesheet" href="../../script/elementui/lib/theme-chalk/index.css?t=1">
    <link href="../../script/elementui/vue-element-table.css" rel="stylesheet" />
    <script type="text/javascript" src="../../script/jquery.js"></script>
    <script type="text/javascript" src="../../script/layer/layer.js"></script>
    <script type="text/javascript" src="../../script/vue.min.js"></script>
    <script type="text/javascript" src="../../script/vant.min.js"></script>
    <script type="text/javascript" src="../../script/fastclick.js"></script>
    <script src="../../script/elementui/lib/index.js?t=1"></script>
    <script src="../../script/elementui/vue-element-bigdata-table.min.js?t=4"></script>
    <script type="text/javascript" src="../../script/base.js"></script>
    <script type="text/javascript" src="../../script/JSLINQ.js"></script>
    <script type="text/javascript" src="../../script/ajaxFileUpload.js"></script>
    <style type="text/css">
        body {
            zoom: 0.9;
        }

        .innerBox {
            flex: 1;
            overflow: auto;
        }

        .mainForm {
            height: auto;
            width: 99%;
            overflow-y: auto;
            display: flex;
            flex-wrap: wrap;
        }

        .van-field {
            width: 50%;
        }

        .van-field__label {
            width: auto;
        }

        .subFrame {
            height: auto;
            padding-bottom: 50px;
        }

        .title {
            width: 25%;
            background-color: #83bff6;
            text-align: center;
            margin: 2px auto 2px 0;
            padding: 4px 1px;
            color: #fff;
            font-size: 17px;
        }

        .table {
            width: auto;
            overflow: auto;
            height: auto;
            border-bottom: 0;
            border-right: 0;
            display: flex;
        }

        .table table {
            width: auto;
            white-space: nowrap;
            table-layout: fixed;
            top: 0;
            flex: 1;
        }

        .table table th {
            width: auto;
            text-align: center;
            padding: auto 5px;
            background-color: lightblue;
            position: sticky;
            top: 0;
            z-index: 1;
        }

        .table table td {
            width: auto;
        }

        .van-icon-delete {
            color: red;
        }

        td {
            text-align: center;
        }

        .equipmentBox {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
        }

        .equipmentBox .van-tag {
            width: 75%;
            margin-top: 4px;
            margin-right: 8px;
        }

        .tagTitlt {
            width: 90%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            display: inline-block;
        }

        .equipmentBox .van-button {
            width: 10%;
            margin-top: 4px;
        }

        input {
            background: none;
            outline: none;
            border: none;
        }

        .van-dialog__confirm,
        .van-dialog__confirm:active {
            color: #1989fa;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box" id="box">
            <van-nav-bar id="van-nav-bar" :title="titleName" left-arrow @click-left="onClickLeft">
                <div slot="right">
                    <span slot="right" @click="openScan" v-if="!isPDA">
                        <img src="../../image/scan.png" />
                    </span>
                    <span slot="right" @click="openPrint" v-if="isPDA && printConfig">
                        <img src="../../image/print.png" />
                    </span>
                </div>
            </van-nav-bar>

            <div class="innerBox">
                <div class="mainForm">
                    <van-field v-model="formData.DOC_NAME" label="单据类型" placeholder="请输入单据类型" readonly>
                    </van-field>
                    <van-field v-model="formData.DOC_NO" label="单据号" placeholder="请输入单据号" readonly></van-field>
                    <van-field v-model="formData.DOCDATE" label="单据日期" placeholder="请输入单据日期" readonly>
                    </van-field>
                    <van-field v-model="formData.ARRIVALDATE" label="到货日期" placeholder="请输入到货日期" readonly>
                    </van-field>
                    <van-field v-model="formData.SUPPLIER_FULL_NAME" label="供应商" placeholder="请输入供应商" readonly>
                    </van-field>
                    <van-field v-model="formData.ADMIN_UNIT_NAME" label="部门" placeholder="请输入部门" readonly>
                    </van-field>
                    <van-field v-model="formData.EMPLOYEE_NAME" label="人员" placeholder="请输入人员" readonly>
                    </van-field>
                    <van-field v-model="formData.REMARK" label="意见备注" placeholder="请输入意见备注" readonly>
                    </van-field>
                    <van-field v-model="formData.UDF021" label="是否生成来料检" placeholder="请输入是否生成来料检" readonly>
                    </van-field>
                </div>

                <div class="subFrame">
                    <div class="title">{{titleName}}明细</div>
                    <div class="table" id="table">
                        <table>
                            <tr>
                                <th>序号</th>
                                <th>品号</th>
                                <th>品名</th>
                                <th>规格</th>
                                <th>图号</th>
                                <th>业务数量</th>
                                <th>来源</th>
                                <th>来源单号</th>
                            </tr>

                            <tr v-for="(item, index) in tableData">
                                <td>
                                    {{index + 1}}
                                </td>
                                <td>
                                    {{item.ProductCode}}
                                </td>
                                <td>
                                    {{item.ProductName}}
                                </td>
                                <td>
                                    {{item.ProcuctSpec}}
                                </td>
                                <td>
                                    {{item.CPTH}}
                                </td>
                                <td>
                                    {{item.BUSINESS_QTY}}
                                </td>
                                <td>
                                    {{item.DOC_NAME}}
                                </td>
                                <td>
                                    {{item.DOC_NO}}
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>

                <div class="bottomSubmit"
                    style="position: fixed;bottom: 0px;z-index: 1;width: 100%;padding: 5px 10px;right:0px">
                    <div style="float:right;width:20%;">
                        <van-button round block type="info" native-type="submit" @click="handlerSubmit">生成来料检
                        </van-button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {

        var FNScanner = api.require('FNScanner');
        var scanTC80 = api.require('scanTC80');
        var escPrinter = api.require('escPrinter');
        var scanS60A = api.require('ScanS60A');
        var scanDT40 = api.require('scanDT40');
        var FNPhotograph = api.require('FNPhotograph');
        var photoBrowser = api.require('photoBrowser');
        var docReader = api.require('docReader');

        api.addEventListener({
            name: 'selectRow'
        }, function (ret, err) {
            // console.log('ret', JSON.stringify(ret))
            if (ret.value.type == '产品') {
                vm.formData.productName = ret.value.row.name
                vm.formData.ProductCode = ret.value.row.ProductCode
            }
        })

        vm = new Vue({
            el: '#app',
            data: {
                titleName: api.pageParam.titleName,
                isPDA: api.deviceModel.indexOf('PDA') > -1 ? true : false,
                serverIP: APP.serverIP(),
                printConfig: '',
                formData: {
                    PURCHASE_ARRIVAL_ID: '',
                    DOC_NAME: '',
                    DOC_NO: '',
                    DOCDATE: '',
                    ARRIVALDATE: '',
                    SUPPLIER_FULL_NAME: '',
                    ADMIN_UNIT_NAME: '',
                    EMPLOYEE_NAME: '',
                    REMARK: '',
                    UDF021: ''
                },
                tableData: [
                    {
                        ProductCode: '',
                        ProductName: '',
                        ProcuctSpec: '',
                        CPTH: '',
                        BUSINESS_QTY: '',
                        DOC_NAME: '',
                        DOC_NO: ''
                    }
                ],
            },
            created: function () {
                var that = this

                if (api.pageParam.historyData) {
                    console.log('api', JSON.stringify(api.pageParam.historyData))
                    that.formData.PURCHASE_ARRIVAL_ID = api.pageParam.historyData.PURCHASE_ARRIVAL_ID
                    APP.ajax('APP_DHDMX', { PURCHASE_ARRIVAL_ID: that.formData.PURCHASE_ARRIVAL_ID }, function (res) {
                        console.log('res', JSON.stringify(res))
                        that.formData = res.ds[0]

                        that.tableData = res.ds1
                    })
                }
            },
            mounted() {
                var navBar = document.getElementById('van-nav-bar')
                navBar.style.paddingTop = api.safeArea.top + 'px'
            },
            methods: {
                onClickLeft() {
                    api.closeWin();
                },

                handlerSubmit() {
                    var that = this
                    APP.ajax('selectLLJByDHDID', { DOC_NO: that.formData.DOC_NO }, function (res) {
                        console.log('res', JSON.stringify(res))
                        if (res.ds[0].STATUS == 200) {
                            APP.ajax('UpdtaeE10DHD', { DOC_NO: that.formData.DOC_NO }, function (res1) {
                                if (res1.ds[0].STATUS == 200) {
                                    api.toast({
                                        msg: res1.ds[0].msg
                                    })
                                    api.sendEvent({
                                        name: 'refresh'
                                    })
                                }
                            })
                        } else {
                            api.toast({
                                msg: res.ds[0].msg
                            })
                            return false
                        }
                    })
                },

                openBaseScreen: function (str, index) {
                    var that = this;
                    that.currentIndex = index
                    var obj;
                    if (str == '产品') {
                        obj = {
                            allowClear: false,
                            showSearch: true,
                            searchKey: '',
                            serverSearch: false,
                            searchBy: ['name'],
                            isPaging: false,
                            type: str,
                            cmd: 'SJJ_CPXL',
                            param: {}
                        }
                    }
                    api.openWin({
                        name: 'baseScreen',
                        url: '../tool/baseScreen.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: obj
                    })
                },

                //摄像头扫描事件
                openScan() {
                    var resultList = api.hasPermission({
                        list: ['camera']
                    });
                    if (resultList[0].granted) {
                        // 已授权，可以继续下一步操作
                        FNScanner.open({
                            autorotation: true
                        }, function (ret, err) {
                            if (ret) {
                                if (ret.content) {
                                    api.sendEvent({
                                        name: 'scanHandler',
                                        extra: {
                                            scanData: ret.content
                                        }
                                    })
                                }
                            } else {
                                vm.$toast('扫描失败');
                            }
                        });
                    } else {
                        api.confirm({
                            msg: '应用需要您的授权才能访问相机',
                            buttons: ['取消', '去设置']
                        }, function (ret) {
                            if (ret.buttonIndex == 2) {
                                api.requestPermission({
                                    list: ['camera'],
                                }, function (res) {
                                    if (res.list[0].granted) {
                                        // 已授权，可以继续下一步操作
                                        FNScanner.open({
                                            autorotation: true
                                        }, function (ret, err) {
                                            if (ret) {
                                                if (ret.content) {
                                                    api.sendEvent({
                                                        name: 'scanHandler',
                                                        extra: {
                                                            scanData: ret.content
                                                        }
                                                    })
                                                }
                                            } else {
                                                vm.$toast('扫描失败');
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }


                    // var hwScanner = api.require('hwScanner');
                    // hwScanner.defaultScanner({
                    //     formatType: 'ALL'
                    // }, function (ret) {
                    //     if (ret.status) {
                    //         api.sendEvent({
                    //             name: 'scanHandler',
                    //             extra: {
                    //                 scanData: ret.result
                    //             }
                    //         })
                    //     }
                    //     else {
                    //         vm.$toast('扫描失败');
                    //     }
                    // });
                },

                //打开打印
                openPrint() {
                    if (vm.printConfig) {
                        var script = vm.printConfig.replace(/\['/g, "vm.formData['");
                        script = script.replace(/\["/g, "vm.formData[\"");
                        eval(script);
                    }
                },

            }
        })
    };
</script>

</html>